package com.shz.controller;


import com.shz.dto.Result;
import com.shz.pojo.Trip;
import com.shz.service.TripService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author shz
 * @since 2024-07-29
 */
@Api(tags = "行程模块")
@RestController
@RequestMapping("/trip")
public class TripController {
    @Resource
    TripService tripService;
    @ApiOperation(value = "该基地行程的所有日期")
    @ApiImplicitParams({@ApiImplicitParam(name = "baseId", value = "基地详情id", required = true),
    })
    @GetMapping("/get/{baseId}")
    public List<LocalDate> getDateList(@PathVariable String baseId){
        List<Trip> list = tripService.query().eq("pid", baseId).list();
        List<LocalDate> collect =  list.stream().map(Trip::getStartdate).collect(Collectors.toList());
        // 筛选出大于今天日期的列表
        List<LocalDate> datesAfterToday = collect.stream()
                .filter(date -> !date.isBefore(LocalDate.now()) && !date.isEqual(LocalDate.now()))
                .collect(Collectors.toList());
        return datesAfterToday;
    }
    @ApiOperation(value = "该基地的所选择日期行程")
    @ApiImplicitParams({@ApiImplicitParam(name = "baseId", value = "基地详情id", required = true),
            @ApiImplicitParam(name = "date", value = "所选日期如2024-7-29这样的字符串", required = true),


    })
    @GetMapping("/getThisRouteTrip/{baseId}/{date}")
    public List<Trip> getThisTripRoute(@PathVariable String baseId,@PathVariable String date){
        LocalDate now = LocalDate.now();
        // 创建一个 DateTimeFormatter 实例
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        // 格式化日期
        String formattedDate = now.format(formatter);
        return tripService.query().eq("startDate",date).eq("pid",baseId).list();
    }

}

